<template>
  <scroll-view scroll-y @scrolltolower="handleTolow" class="cate_wrap">
    <!-- 这是类别为{{name}}页面 -->
    <block v-for="(item,index) in coursesList" :key="index">
      <courseList
        :item="item"
        :index="index"
        @ClickAppreciate="clickAppreciate"
        @ClickComment="clickComment"
        @ClickShare="clickShare"
        @ClickTitlePic="clickTitlepic"
      ></courseList>
    </block>
  </scroll-view>
</template>

<script>
import courseList from "../../component/courseList.vue";
export default {
  components:{
    courseList
  },
  data() {
    return {
      name: "",
      coursesList: [],
      hasMore: true, //是否还有更多数据
      params: {
        //获取更多的参数
        limit: 10,
        skip: 0
      }
    };
  },
  methods: {
    getList() {
      this.request({
        url:
          this.apiServer +
          "/courses/findCoursesByType?type=" +
          this.name +
          "&skip=" +
          this.params.skip +
          "&limit=" +
          this.params.limit
      }).then(res => {
        console.log(res);
        if (res.data.length === 0) {
          this.hasMore = false;
          return;
        }
        this.coursesList = [...this.coursesList, ...res.data]; //拼接list
      });
    },
    handleTolow() {
      console.log("到底啦");
      if (this.hasMore) {
        //还有更多的话修改参数
        this.params.skip += this.params.limit;
        this.getList();
      } else {
        uni.showToast({
          title: "已经没有数据了啦!",
          icon: "none"
        });
      }
    }
  },
  onLoad(option) {
    console.log(option);
    this.name = option.name;
    //setBar
    uni.setNavigationBarTitle({
      title: option.name+"课程页面"
    });
    this.getList();
  }
};
</script>

<style lang="scss" scoped>
.cate_wrap {
  height: calc(100vh - 35px);
}
</style>